home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / HENSA / MATHS / PLPLOT / PLPLOT.ZIP / examples / C / x18c.c < prev    next >
C/C++ Source or Header  |  1994-08-10  |  4KB  |  187 lines

  1. /* $Id: x18c.c,v 1.6 1994/08/10 01:13:12 mjl Exp $
  2.  * $Log: x18c.c,v $
  3.  * Revision 1.6  1994/08/10  01:13:12  mjl
  4.  * Put in conditional for PI define.
  5.  *
  6.  * Revision 1.5  1994/07/22  16:03:29  furnish
  7.  * "Little Miss Muffet, sat on a tuffet, eating her curds and whey.
  8.  * Along came a spider and sat down beside her, and frightened Miss
  9.  * Muffet away."
  10.  *
  11.  * Revision 1.4  1994/07/21  10:12:10  mjl
  12.  * Changed plpoin3 to use fast point draw (code=-1).
  13.  *
  14.  * Revision 1.3  1994/07/20  06:06:12  mjl
  15.  * Minor changes to make it easier to play with the altitude/azimuth
  16.  * settings.  Changed to the new API calls for the 3d functions.
  17.  *
  18.  * Revision 1.2  1994/07/19  22:14:05  furnish
  19.  * Added new plots for showing hidden surface removal using pl3poly().
  20.  *
  21.  * Revision 1.1  1994/07/15  20:38:09  furnish
  22.  * Example program to show off 3-d line and point plotting.
  23. */
  24.  
  25. /*    x18c.c
  26.  
  27.     3-d line and point plot demo.  Adapted from x08c.c.
  28. */
  29.  
  30. #include <plplot.h>
  31.  
  32. #ifndef PI
  33. #define PI 3.1415927
  34. #endif
  35.  
  36. static int opt[] =
  37. { 1, 0, 1, 0 };
  38.  
  39. static PLFLT alt[] =
  40. {20.0, 35.0, 50.0, 65.0};
  41.  
  42. static PLFLT az[] =
  43. {30.0, 40.0, 50.0, 60.0};
  44.  
  45. void test_poly();
  46.  
  47. /*----------------------------------------------------------------------*\
  48.  * main
  49.  *
  50.  * Does a series of 3-d plots for a given data set, with different
  51.  * viewing options in each plot.
  52. \*----------------------------------------------------------------------*/
  53.  
  54. #define NPTS 1000
  55.  
  56. int
  57. main(int argc, char *argv[])
  58. {
  59.     int i, j, k;
  60.     PLFLT *x, *y, *z;
  61.     PLFLT r;
  62.     char title[80];
  63.  
  64. /* Parse and process command line arguments */
  65.  
  66.     (void) plParseInternalOpts(&argc, argv, PL_PARSE_FULL);
  67.  
  68. /* Initialize plplot */
  69.  
  70.     plinit();
  71.  
  72.     for( k=0; k < 4; k++ )
  73.     test_poly(k);
  74.  
  75.     x = (PLFLT *) malloc(NPTS * sizeof(PLFLT));
  76.     y = (PLFLT *) malloc(NPTS * sizeof(PLFLT));
  77.     z = (PLFLT *) malloc(NPTS * sizeof(PLFLT));
  78.  
  79. /* From the mind of a sick and twisted physicist... */
  80.  
  81.     for (i = 0; i < NPTS; i++) {
  82.     z[i] = -1. + 2. * i / NPTS;
  83.  
  84. /* Pick one ... */
  85.  
  86. /*    r    = 1. - ( (float) i / (float) NPTS ); */
  87.     r    = z[i];
  88.  
  89.     x[i] = r * cos( 2. * PI * 6. * i / NPTS );
  90.     y[i] = r * sin( 2. * PI * 6. * i / NPTS );
  91.     }
  92.  
  93.     for (k = 0; k < 4; k++) {
  94.     pladv(0);
  95.     plvpor(0.0, 1.0, 0.0, 0.9);
  96.     plwind(-1.0, 1.0, -0.9, 1.1);
  97.     plcol(1);
  98.     plw3d(1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, alt[k], az[k]);
  99.     plbox3("bnstu", "x axis", 0.0, 0,
  100.            "bnstu", "y axis", 0.0, 0,
  101.            "bcdmnstuv", "z axis", 0.0, 0);
  102.  
  103.     plcol(2);
  104.  
  105.     if (opt[k])
  106.         plline3( NPTS, x, y, z );
  107.     else
  108.         plpoin3( NPTS, x, y, z, -1 );
  109.  
  110.     plcol(3);
  111.     sprintf(title, "#frPLplot Example 18 - Alt=%.0f, Az=%.0f",
  112.         alt[k], az[k]);
  113.     plmtex("t", 1.0, 0.5, 0.5, title);
  114.     }
  115.  
  116.     plend();
  117.     exit(0);
  118. }
  119.  
  120. void test_poly(int k)
  121. {
  122.     float *x, *y, *z;
  123.     float theta, phi;
  124.     int i, j;
  125.     float pi, two_pi;
  126.     int draw[][4] = { { 1, 1, 1, 1 },
  127.               { 1, 0, 1, 0 },
  128.               { 0, 1, 0, 1 },
  129.               { 1, 1, 0, 0 } };
  130.  
  131.     pi = 3.1415927, two_pi = 2. * pi;
  132.  
  133.     x = (PLFLT *) malloc(5 * sizeof(PLFLT));
  134.     y = (PLFLT *) malloc(5 * sizeof(PLFLT));
  135.     z = (PLFLT *) malloc(5 * sizeof(PLFLT));
  136.  
  137.     pladv(0);
  138.     plvpor(0.0, 1.0, 0.0, 0.9);
  139.     plwind(-1.0, 1.0, -0.9, 1.1);
  140.     plcol(1);
  141.     plw3d(1.0, 1.0, 1.0, -1.0, 1.0, -1.0, 1.0, -1.0, 1.0, alt[k], az[k]);
  142.     plbox3("bnstu", "x axis", 0.0, 0,
  143.        "bnstu", "y axis", 0.0, 0,
  144.        "bcdmnstuv", "z axis", 0.0, 0);
  145.  
  146.     plcol(2);
  147.  
  148. #define THETA(a) (two_pi * (a) /20.)
  149. #define PHI(a)    (pi * (a) / 20.1)
  150.  
  151. /*
  152.   x = r sin(phi) cos(theta)
  153.   y = r sin(phi) sin(theta)
  154.   z = r cos(phi)
  155.   r = 1 :=)
  156.   */
  157.  
  158.     for( i=0; i < 20; i++ ) {
  159.     for( j=0; j < 20; j++ ) {
  160.         x[0] = sin( PHI(j) ) * cos( THETA(i) );
  161.         y[0] = sin( PHI(j) ) * sin( THETA(i) );
  162.         z[0] = cos( PHI(j) );
  163.         
  164.         x[1] = sin( PHI(j+1) ) * cos( THETA(i) );
  165.         y[1] = sin( PHI(j+1) ) * sin( THETA(i) );
  166.         z[1] = cos( PHI(j+1) );
  167.         
  168.         x[2] = sin( PHI(j+1) ) * cos( THETA(i+1) );
  169.         y[2] = sin( PHI(j+1) ) * sin( THETA(i+1) );
  170.         z[2] = cos( PHI(j+1) );
  171.         
  172.         x[3] = sin( PHI(j) ) * cos( THETA(i+1) );
  173.         y[3] = sin( PHI(j) ) * sin( THETA(i+1) );
  174.         z[3] = cos( PHI(j) );
  175.         
  176.         x[4] = sin( PHI(j) ) * cos( THETA(i) );
  177.         y[4] = sin( PHI(j) ) * sin( THETA(i) );
  178.         z[4] = cos( PHI(j) );
  179.  
  180.         plpoly3( -5, x, y, z, draw[k] );
  181.     }
  182.     }
  183.  
  184.     plcol(3);
  185.     plmtex("t", 1.0, 0.5, 0.5, "unit radius sphere" );
  186. }
  187.